var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabs: ['全部', '待成团', '待使用', '已使用'],
    tabIndex: 0,
    navigator: { hide: 0 },
    list: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that =this;
    //快速导航
    app.ihttpGet("https://www.58zltc.com/api.php/Index/getNav", function (res) {
      var v = that.data.navigator;
      v.info = res.data
      that.setData({
        navigator: v
      })
    })
    //屏幕宽度
    wx.getSystemInfo({
      success: function (res) {
        var width = res.screenWidth;
        var v = that.data.navigator;
        v.width = width
        that.setData({
          navigator: v
        })
      },
    })

    //实例化一个动画
    this.animation = wx.createAnimation({
      // 动画持续时间，单位ms，默认值 400
      duration: 300,
      /**
       * linear 动画一直较为均匀
       * ease  从匀速到加速在到匀速
       * ease-in 缓慢到匀速
       * ease-in-out 从缓慢到匀速再到缓慢
       * step-start 动画一开始就跳到 100% 直到动画持续时间结束 一闪而过
       * step-end  保持 0% 的样式直到动画持续时间结束    一闪而过
       */
      timingFunction: 'ease',
      // 延迟多长时间开始
      delay: 100,
      /**
       * 以什么为基点做动画 效果自己演示
       * left,center right是水平方向取值，对应的百分值为left=0%;center=50%;right=100%
       * top center bottom是垂直方向的取值，其中top=0%;center=50%;bottom=100%
       */
      transformOrigin: 'right',
      success: function (res) {

      }
    })
    var width = this.data.navigator.width;
    var offset = width * 0.64;
    that.animation.translateX(offset).step()
    var v = this.data.navigator
    v.animation = that.animation.export()
    v.hide = 1
    that.setData({
      //输出动画
      navigator: v
    })
    if (options.tabIndex) {
      that.setData({
        tabIndex: options.tabIndex
      })
    }
    wx.showLoading({
      title: '加载中',
    })
    setTimeout(function () {
      that.getlist();
      wx.hideLoading();
    }, 500)

  },
  //快捷导航
  navigator: function (e) {
    var width = this.data.navigator.width
    if (this.data.navigator.hide == 1) {
      var offset = '0'
      var mum = 0;
    } else {
      var offset = width * 0.64
      var mum = 1;
    }
    this.animation.translateX(offset).step()
    var v = this.data.navigator
    v.animation = this.animation.export();
    v.hide = mum;
    this.setData({
      //输出动画
      navigator: v
    })
  },
  onShow: function () {
    this.onLoad();
  },
  getlist:function(e){
    let that = this;
    wx.showLoading({
      title: '加载中…',
    })
    app.ihttpGet('https://www.58zltc.com/api.php/Order/index/openid/' + app.globalData.openid, function (res) {
      that.setData({
        list: res.data
      })
    })
  },

  setTab: function(e){
    this.setData({
      tabIndex: e.currentTarget.dataset.index
    })
  },
  backto: function () {
    wx.navigateBack({
      
    })
  },
  jumpPing: function (e) {
    console.log(e)
    wx.navigateTo({
      url: '/pages/mine/ping/ping',
    })
  }
})